package com.ns.sbs.oauth.minio.service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ns.sbs.oauth.minio.conf.MinioTemplate;
import com.ns.sbs.oauth.minio.entry.MinioItem;
import com.ns.sbs.oauth.minio.mapper.MinioFileMapper;
import com.ns.sbs.oauth.minio.vo.MinioItemVO;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * 文件处理
 *
 * @author liao.wei
 * @since 2022/11/2
 */
@Service
@RequiredArgsConstructor
@Slf4j
@Transactional(rollbackFor = Exception.class)
public class MinioFileServiceImpl extends ServiceImpl<MinioFileMapper, MinioItem> implements IMinioFileService {
    private final MinioTemplate minioTemplate;

    @Override
    public void existBucket(String name) {
        minioTemplate.existBucket(name);
    }

    @Override
    public Boolean makeBucket(String bucketName) {
        return minioTemplate.makeBucket(bucketName);
    }

    @Override
    public Boolean removeBucket(String bucketName) {
        return minioTemplate.removeBucket(bucketName);
    }

    @Override
    public MinioItemVO upload(MultipartFile file) {
        return minioTemplate.upload(file);
    }

    @Override
    public void fileDownload(String fileName, Boolean delete, HttpServletResponse response) {
        minioTemplate.fileDownload(fileName, delete, response);
    }

    @Override
    public List<MinioItemVO> listObjects(String bucketName) {
        return minioTemplate.listObjects(bucketName);
    }

    @Override
    public Boolean removeObjects(String bucketName, List<String> objects) {
        return minioTemplate.removeObjects(bucketName, objects);
    }
}
